package com.msb.singleton;

/**
 * @Auther： WangLei
 * @Date： 2021/8/13-08-13-22:14
 * @Description: com.msb.singleton
 * @version: 1.0
 */
public class LazyBonesSync2 {
    private static LazyBonesSync2 instance = null;
    private LazyBonesSync2(){}

    public static LazyBonesSync2 getInstance(){

        if(instance == null){
            synchronized (LazyBonesSync2.class){
                if(instance == null){
                    try {
                        Thread.sleep(10);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    instance = new LazyBonesSync2();
                }
            }
        }

        return instance;
    }


    public static void main(String[] args) {
        for(int i = 0;i < 100 ; i++){
            new Thread(() ->
                    System.out.println(LazyBonesSync2.getInstance().hashCode())
            ).start();
        }

    }
}
